<?php

/**
 * Created by Sven.
 * Date: 2017/1/1
 * Time: 20:49
 */
class ListAction extends Action {

    public function  __construct( $_tpl ) {
        $_model = new ContentModel();
        parent::__construct( $_tpl, $_model );
    }

    public function action() {
        // empty method
    }

    public function getList(){
        if (isset($_GET['nav_id'])){
            $_navId = intval($_GET['nav_id']);
            if ($_navId > 0){
                $this->model->nav = $_GET['nav_id'];
                // 获取该类所有文章
//                $_allList = $this->model->getContentList();

                // 获取该类和子类下所有文章：第1种方法
//                $_allList = array();
//                $this->model->getAllSubContent1($_navId, $_allList,  new NavModel());

                // 获取该类和子类下所有文章：第2种方法

                // 分页
                $_total = $this->model->getListCount();
                $this->page($_total, ARTICLE_PAGE_SIZE);
                $_allList = $this->model->getAllSubContent2();

                foreach ($_allList as $_value){
                    $_value->info = strip_tags($_value->info); // 处理摘要中的html标签
                    $_value->info = Tool::cutString($_value->info,  120);
                    $_value->title = Tool::cutString($_value->title,  35);
                }

//                var_dump($_allList);
                $this->tpl->assign('AllList', $_allList);


            } else {
                Tool::alertBack('警告：非法的ID值');
            }

        } else {
            Tool::alertBack('警告：非法的ID值');
        }

    }

}

